using System;
using System.Globalization;
using System.IO;
using System.Windows.Forms;

namespace YulgangMarkup
{
	public static class Config
	{
		public static int AbilityDescONESpacing
		{
			get;
			set;
		}

		public static int AbilityDescTWOSpacing
		{
			get;
			set;
		}

		public static int AbilityJumpValue
		{
			get;
			set;
		}

		public static int AbilityNameSpacing
		{
			get;
			set;
		}

		public static int AbilityStartPosition
		{
			get;
			set;
		}

		public static int BadwordJumpValue
		{
			get;
			set;
		}

		public static int BadwordStartPosition
		{
			get;
			set;
		}

		public static int ItemDescSpacing
		{
			get;
			set;
		}

		public static int ItemJumpValue
		{
			get;
			set;
		}

		public static int ItemNameSpacing
		{
			get;
			set;
		}

		public static int ItemStartPosition
		{
			get;
			set;
		}

		public static int MapJumpValue
		{
			get;
			set;
		}

		public static int MapNameSpacing
		{
			get;
			set;
		}

		public static int MapStartPosition
		{
			get;
			set;
		}

		public static int NPCDescSpacing
		{
			get;
			set;
		}

		public static int NPCJumpValue
		{
			get;
			set;
		}

		public static int NPCNameSpacing
		{
			get;
			set;
		}

		public static int NPCStartPosition
		{
			get;
			set;
		}

		public static int SkillDescSpacing
		{
			get;
			set;
		}

		public static int SkillJumpOne
		{
			get;
			set;
		}

		public static int SkillJumpTwo
		{
			get;
			set;
		}

		public static int SkillJumpThr
		{
			get;
			set;
		}

		public static int SkillNameSpacing
		{
			get;
			set;
		}

		public static int SkillStartPosition
		{
			get;
			set;
		}

		public static int SpeechJumpValue
		{
			get;
			set;
		}

		public static int SpeechStartPosition
		{
			get;
			set;
		}

		public static int SpeechTextSpacing
		{
			get;
			set;
		}

		public static int IniReadValue(string Key)
		{
			try
			{
				string text = "";
				string[] array = File.ReadAllLines(Application.StartupPath + "\\ybi.ini");
				string[] array2 = array;
				string[] array3 = array2;
				foreach (string text2 in array3)
				{
					if (!text2.Contains("#") && !text2.Contains("/") && !text2.Contains("[") && text2.Contains("=") && text2.Contains(Key))
					{
						text = text2;
						break;
					}
				}
				char[] separator = new char[1]
				{
					'='
				};
				text = text.Split(separator)[1];
				if (text.Contains("0x"))
				{
					return int.Parse(text.Replace("0x", ""), NumberStyles.HexNumber);
				}
				return int.Parse(text);
			}
			catch
			{
				MessageBox.Show("Error while loading Key '" + Key + "'!\nPlease double check your ybi.ini!", "An error occured!", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				Environment.Exit(0);
				return 0;
			}
		}

		public static void LoadConfig()
		{
			ItemStartPosition = IniReadValue("ItemStart");
			ItemJumpValue = IniReadValue("ItemJump");
			ItemNameSpacing = IniReadValue("ItemNameSpacing");
			ItemDescSpacing = IniReadValue("ItemDescSpacing");
			NPCStartPosition = IniReadValue("NPCStartPosition");
			NPCJumpValue = IniReadValue("NPCJumpValue");
			NPCNameSpacing = IniReadValue("NPCNameSpacing");
			NPCDescSpacing = IniReadValue("NPCDescSpacing");
			AbilityStartPosition = IniReadValue("AbilityStartPosition");
			AbilityJumpValue = IniReadValue("AbilityJumpValue");
			AbilityNameSpacing = IniReadValue("AbilityNameSpacing");
			AbilityDescONESpacing = IniReadValue("AbilityDescONESpacing");
			AbilityDescTWOSpacing = IniReadValue("AbilityDescTWOSpacing");
			MapStartPosition = IniReadValue("MapStartPosition");
			MapJumpValue = IniReadValue("MapJumpValue");
			MapNameSpacing = IniReadValue("MapNameSpacing");
			SkillStartPosition = IniReadValue("SkillStartPosition");
			SkillJumpOne = IniReadValue("SkillJumpOne");
			SkillJumpTwo = IniReadValue("SkillJumpTwo");
			SkillJumpThr = IniReadValue("SkillJumpThr");
			SkillNameSpacing = IniReadValue("SkillNameSpacing");
			SkillDescSpacing = IniReadValue("SkillDescSpacing");
			BadwordStartPosition = IniReadValue("BadwordStartPosition");
			BadwordJumpValue = IniReadValue("BadwordJumpValue");
			SpeechStartPosition = IniReadValue("SpeechStartPosition");
			SpeechJumpValue = IniReadValue("SpeechJumpValue");
			SpeechTextSpacing = IniReadValue("SpeechTextSpacing");
		}
	}
}
